
#生成全局环境变量
#/bin/sh

currentPath=$(cd `dirname $0`;pwd)
softHome=$(cd `readlink -f $currentPath/../..`;pwd)
etcHome="$softHome/conf/etc"
#serviceHome=$(cd `readlink -f $softHome/conf/service`;pwd)
serviceHome="/lib/systemd/system"
k8ServerBin=$(cd `readlink -f $softHome/kubernetes/kubernetes-server/server/bin`;pwd)
k8NodeBin=$(cd `readlink -f $softHome/kubernetes/kubernetes-node/node/bin`;pwd)
k8ClientBin=$(cd `readlink -f $softHome/kubernetes/kubernetes-client/client/bin`;pwd)
k8FlannelBin=$(cd `readlink -f $softHome/flannel`;pwd)
k8ConfigHome="$etcHome/kubernetes"
k8CertHome="$etcHome/cert"
etcdBin=$(cd `readlink -f $softHome/etcd-v3.3.10-linux-amd64`;pwd)
cfsslBin="$softHome/cfssl"
tempService="$currentPath/build/service"
for dir in $k8ConfigHome $k8CertHome $tempService
do
    if [ ! -d $dir ]; then
        mkdir -p $dir
    fi
done

environmentFile="build/environment.bashrc"

echo "# kubernetes soft info " > $environmentFile

echo "export K8_CERT_HOME=$k8CertHome" >> $environmentFile


echo "export K8_SOFT_HOME=$softHome" >> $environmentFile
echo "export K8_ETC_HOME=$etcHome" >> $environmentFile
echo "export K8_SERVICE_HOME=$serviceHome" >> $environmentFile


echo "export K8_CONFIG_HOME=$k8ConfigHome" >> $environmentFile
echo "export K8_SERVER_BIN=$k8ServerBin" >> $environmentFile
echo "export K8_NODE_BIN=$k8NodeBin" >> $environmentFile
echo "export K8_CLIENT_BIN=$k8ClientBin" >> $environmentFile
echo "export K8_FLANNEL_BIN=$k8FlannelBin" >> $environmentFile
echo "export K8_ETCD_BIN=$etcdBin" >> $environmentFile
echo "export K8_CFSSL_BIN=$cfsslBin" >> $environmentFile
echo "export PATH=$PATH:\$K8_SERVER_BIN:\$K8_NODE_BIN:\$K8_CLIENT_BIN:\$K8_FLANNEL_BIN:\$K8_ETCD_BIN:\$K8_CFSSL_BIN" >> $environmentFile

nodeShell="$currentPath/build/k8_node.sh"
masterShell="$currentPath/build/k8_master.sh"

echo "export K8_NODE_SHELL=$nodeShell" >> $environmentFile
echo "export K8_MASTER_SHELL=$masterShell" >> $environmentFile
echo "#node shell" > $nodeShell
echo "systemctl daemon-reload " >> $nodeShell
echo "#master shell " > $masterShell
echo "systemctl daemon-reload " >> $masterShell

chmod +x $nodeShell
chmod +x $masterShell

echo "export K8_MASTER_HOST=10.2.238.250" >> $environmentFile
echo "export K8_SERVICE_CLUSTER_IP_RANGE=10.254.0.0/16" >> $environmentFile
echo "export K8_CLUSTER_DNS=10.254.0.10" >> $environmentFile


tokenValue=$(head -c 16 /dev/urandom | od -An -t x | tr -d ' ')
echo "$tokenValue,10001,\"system:kubelet-bootstrap\"" > $k8ConfigHome/token.csv




